package controller;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.mybatis.po.Commentinfo;

import service.CommentService;
import util.MySessionContext;

@CrossOrigin(originPatterns="*",allowCredentials="true")
@Controller
@RequestMapping("comment")

public class Comment {
	@Autowired
	private CommentService commentservice;
	@RequestMapping("add")
	@ResponseBody
	public int add(String sid,String cid,String cname,String comments) {
		MySessionContext myc= MySessionContext.getInstance();
		HttpSession session = myc.getSession(sid);
		Commentinfo commentinfo=new Commentinfo();
		commentinfo.setUid((String)session.getAttribute("Uid"));
		commentinfo.setUname((String)session.getAttribute("Uname"));
		commentinfo.setCid(cid);
		commentinfo.setCname(cname);
		commentinfo.setComments(comments);
		return commentservice.addcomment(commentinfo);
	}
	
	@RequestMapping("selectstudent")
	@ResponseBody
	public List<Commentinfo> select(String cid){
		return commentservice.selectcomment1(cid);
	}
	@RequestMapping("selectteacher")
	@ResponseBody
	public List<Commentinfo> select1(String tid){
		return commentservice.selectcomment2(tid);
	}
}
